/*
 * @Author: fhw
 * @Date: 2022-07-25 17:15:03
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-11-18 16:34:09
 * @Description: 拦截器转换格式
 */
import { Injectable, NestInterceptor, CallHandler, ExecutionContext } from '@nestjs/common'
import { map } from 'rxjs/operators'
import { Observable } from 'rxjs'
interface Response<T> {
  data: T
}
@Injectable()
export class TransformInterceptor<T> implements NestInterceptor<T, Response<T>> {
  intercept(context: ExecutionContext, next: CallHandler<T>): Observable<Response<T>> {
    return next.handle().pipe(
      map((data) => {
        return {
          data,
          code: '200',
          msg: '请求成功',
          success: true,
        }
      }),
    )
  }
}
